﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WareHouseMngr.aspx.cs" Inherits="Stock_WareHouseMngr" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>仓库设定</title>
    <link href="../js/jquery-easyui-1.2.6/themes/default/easyui.css" rel="stylesheet"
        type="text/css" />
    <script src="../js/jquery-easyui-1.2.6/jquery-1.7.2.min.js" type="text/javascript"></script>
     <script src="../js/json2.js" type="text/javascript"></script>  
    <script src="../js/jquery-easyui-1.2.6/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../js/jquery-easyui-1.2.6/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <link href="../css/wms.css" rel="stylesheet" type="text/css" />
    <link href="../css/icon.css" rel="stylesheet" type="text/css" />
        <script src="../js/json2.js" type="text/javascript"></script>
    <style type="text/css">
      #editWhs td{ line-height:35px;}
    </style>
    <script type="text/javascript">
        var grd;
        var dlgEdit;
        var dlgEditForm;
        var page = {handlePrix: "../handleControl/WarehouseMngr.ashx?func="};

        $(function () {
            grd = $('#whsListTable').datagrid({
            title:"仓库维护",
            nowrap: true,
            striped: true,
            remoteSort: false,
            fitColumns: true,
            pageSize: 10,
            url: page.handlePrix + "GetAllWhsInfo&whNo=" + jQuery("#whNo").val(),
            frozenColumns: [[
                    { field: 'ck', checkbox: true }
                ]],
            columns: [[
                    { field: 'WHS_WHS', title: '仓库编号', width: 100 },
                    { field: 'WHS_DESN', title: '仓库描述', width: 100 },
                    { field: 'Operate', title: '操作', width: 70, align: 'center',
                        formatter: function (value, whs, index) {
                            var e = '<a onclick="Edit(\'' + whs.WHS_WHS + '\');" title="编辑" iconcls="icon-edit-blue" class="easyui-linkbutton l-btn l-btn-plain" plain="true"><span class="l-btn-left"><span class="l-btn-text"><span class="l-btn-empty icon-edit-blue">&nbsp;</span></span></span></a>';
                            var d = '<a onclick="Delete(\'' + whs.WHS_WHS + '\')" title="删除" iconcls="icon-delete" class="easyui-linkbutton l-btn l-btn-plain" plain="true"><span class="l-btn-left"><span class="l-btn-text"><span class="l-btn-empty icon-delete">&nbsp;</span></span></span></a>';
                            return e + d;
                        }
                    }
                ]],
           // pagination: true,
            rownumbers: true,
            toolbar:
                    [{
                        id: 'btnAdd',
                        text: '添加',
                        iconCls: 'icon-add-blue',
                        handler: Add
                    },
                    '-',
                    {
                        id: 'btnDelete',
                        text: '批量删除',
                        iconCls: 'icon-delete',
                        handler: function () {
                            var rows = $("#whsListTable").datagrid("getSelections");

                            if (rows.length == 0) {
                                $.messager.show({
                                    title: '操作提示',
                                    msg: '请选择您要删除的记录！',
                                    showType: 'slide',
                                    timeout: 3000
                                });
                            }
                            else {
                                $.messager.confirm("操作提示", "您确定要删除选中的记录吗？", function (data) {
                                    if (data) {
                                        var idlist = [];

                                        $.each(rows, function (i, row) {
                                            idlist.push(row.WHS_WHS);
                                        });

                                        $.ajax({
                                            type: "POST",
                                            url: page.handlePrix + "DelWhsByID",
                                            data: "ids=" + idlist.join(','),
                                            success: function (data) {
                                                eval('data=' + data);
                                                if (data.success) {
                                                    $.messager.alert('操作提示', '删除成功！', "info", function () {
                                                        $('#whsListTable').datagrid("reload");
                                                    });
                                                }
                                                else {
                                                    $.messager.alert('数据操作异常', data.message, "error");
                                                }
                                            },
                                            error: function () {
                                                $.messager.alert('异步操作异常', '异步操作错误！', "error");
                                            }
                                        });
                                    }
                                });
                            }
                        }
                    }
                ]
        });

            dlgEdit = $("#editWhs").dialog({
                closed: true,
                width: 400,
                height: 300,
                closable: true,
                draggable: true,
                resizable: false,
                modal: true,
                buttons:
                [
                    {
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: Save
                    },
				    {
				        text: '取消',
				        iconCls: 'icon-cancel',
				        handler: function () {
				            dlgEdit.dialog('close');
				        }
				    }
				],
                onClose: function () {
                    grd.datagrid('clearSelections');
                }
            });

            dlgEditForm = dlgEdit.find('form');
        });

        // 添加
        function Add() {
            jQuery("#whsNoTxt").val("");
            jQuery("#whsDescTxt").val("");
            dlgEdit.dialog('open');
            dlgEditForm.url = page.handlePrix + "AddWhs";
            jQuery("#whsNoTxt").focus();
        }

        // 编辑
        function Edit(no) {
    
          jQuery.get(page.handlePrix + "GetWhsInfoByNo", { no: no, rd: parseInt(Math.random(1) * 10000) }, function (data) {
              var dt = JSON.parse(data);
              jQuery("#whsNoTxt").attr("disabled", true);
              jQuery("#whsNoTxt").val(dt.list["WhsWhs"]);
              jQuery("#whsDescTxt").val(dt.list["WhsDesc"]); ;
          });
           dlgEdit.dialog('open');
            dlgEditForm.url = page.handlePrix + "ModifyWhs&no="+no;
        }

        // 删除
        function Delete(no) {
            $.messager.confirm("操作提示", "您确定要删除选中的记录吗？", function (data) {
                if (data) {
                    $.ajax({
                        type: "POST",
                        url: page.handlePrix+"DelWhsByID",
                        data: "ids=" + no,
                        success: function (data) {
                            eval('data=' + data);
                            if (data.success) {
                                $.messager.alert('操作提示', '删除成功！', "info", function () {
                                    grd.datagrid("reload");
                                });
                            }
                            else {
                                $.messager.alert('操作提示',"数据不存在" , "error");
                            }
                        },
                        error: function () {
                            $.messager.alert('异步操作异常', '异步操作错误！', "error");
                        }
                    });
                }
                else {
                    grd.datagrid('clearSelections');
                }
            });
        }

        // 保存
        function Save() {
            var whsWhs = jQuery.trim(jQuery("#whsNoTxt").val());
            var whsDesc = jQuery.trim(jQuery("#whsDescTxt").val());

              if (whsWhs == "" || whsDesc == "") {
                $.messager.alert("提示", "必须填入编码与描述信息", "error");
                return;
            }

            dlgEditForm.form('submit', {
                url: dlgEditForm.url,
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (data) {
                    if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
                        dlgEdit.dialog('close');
                        $.messager.alert('操作提示', '保存成功！', "info", function () {
                            grd.datagrid("reload");
                        });
                    } else {
                        eval('data=' + data);
                        if (data.success) {
                            $.messager.alert('操作提示', '保存成功！', "info", function () {
                                dlgEdit.dialog('close');
                                grd.datagrid("reload");
                            });
                        }
                        else {
                            $.messager.alert('操作提示', "此仓库的信息已存在", "error");
                        }
                    }
                }
            });
        }

        // 查询
        function Search() {
            grd.datagrid('options').url = page.handlePrix + "GetAllWhsInfo&whNo="+encodeURI( jQuery("#whNo").val());
            grd.datagrid("reload");
        }

        // 清空
        function Reset() {
            $("#whNo").val("");
            grd.datagrid('options').url = page.handlePrix + "GetAllWhsInfo&whNo=" + encodeURI(jQuery("#whNo").val());
            grd.datagrid("reload");
        }



        $(function () {
            jQuery("#whNo").focus();
            // 查询条件
            $("#search").bind("click", function () {
                Search();
            });
            // 清空
            $("#reset").bind("click", function () {
                Reset();
            });

        });



    </script>
    
</head>
<body>
    <div id="main">
        <div class="easyui-panel" title="查询条件" iconcls="icon-search" collapsible="true">
            <div class="search-condition">
                <div>
                    仓库编号：<input id="whNo" type="text" />
            <a id="search" class="easyui-linkbutton" plain="true" iconcls="icon-search">查询</a>
            <a id="reset" class="easyui-linkbutton" plain="true" iconcls="icon-empty">清空</a>
                </div>
            </div>
        </div>
        <table id="whsListTable" style="margin-top: 5px; clear: both;">
        </table>
    </div>
    <div id="editWhs" title="仓库维护">
        <form id="from1" method="post">
        <div style="margin-left:30px;">
        <table style="text-align:center;">
            <tr>
                <td>
                    仓库代码：
                </td>
                <td style=" text-align:left;">
                    <input type="text" id="whsNoTxt" name="whsNoTxt" maxlength="2"  />
                </td>
             </tr>
             <tr>
                <td>
                    仓库说明：
                </td>
                <td style=" text-align:left;">
                <textarea  id="whsDescTxt" name ="whsDescTxt" style=" height:100px;">
                </textarea>
  
                </td>
            </tr>
        </table>
        </div>
        </form>
    </div>

  
</body>
</html>
